package com.workflow.workflowproject.controller;

import com.workflow.workflowproject.entity.FlowForm;
import com.workflow.workflowproject.entity.FlowInfo;
import com.workflow.workflowproject.entity.FlowVersion;
import com.workflow.workflowproject.service.FlowFormService;
import com.workflow.workflowproject.tools.Result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "表单信息")
@RequestMapping("/flowForm")
public class FlowFormController {

    @Autowired
    private FlowFormService flowFormService;
    /**
     * 添加流程表单版本信息
     *
     * @param
     * @return
     */
    @PostMapping
    @Operation(summary="添加流程表单版本信息",description="添加流程表单版本信息")
    public Result addFlowForm(@RequestBody FlowForm flowForm) throws Exception{
        return flowFormService.addFlowForm(flowForm);
    }
    /**
     * 修改流程表单版本信息
     *
     * @param
     * @return
     */
    @PutMapping("/{id}/{type}")
    @Operation(summary="修改流程表单版本信息",description="修改流程表单版本信息")
    public Result updateFlowForm(@PathVariable String id, @PathVariable Integer type,@RequestBody FlowForm flowForm) throws Exception{
        return flowFormService.updateFlowForm(id,type,flowForm);
    }
    /**
     * 通过id查询流程表单版本
     *
     * @param
     * @return
     */
    @GetMapping("/{id}")
    @Operation(summary="通过id查询流程表单版本",description="通过id查询流程表单版本")
    public Result getFlowFormById(@PathVariable Long id) throws Exception{
        return flowFormService.getFlowFormById(id);
    }
    /**
     * 通过流程信息id查询流程表单版本
     *
     * @param
     * @return
     */
    @GetMapping("/search")
    @Operation(summary="通过流程信息id查询流程表单版本",description="通过流程信息id查询流程表单版本")
    public Result getFlowFormByFlowInfoId(@RequestParam("flowInfoId") Integer flowInfoId) throws Exception{
        return flowFormService.getFlowFormByFlowInfoId(flowInfoId);
    }

    /**
     * 通过流程信息id查询上线的表单
     *
     * @param
     * @return
     */
    @GetMapping("/processOnlineForm")
    @Operation(summary="通过流程信息id查询上线的表单",description="通过流程信息id查询流程表单版本")
    public Result processOnlineForm(@RequestParam("flowInfoId") Integer flowInfoId) throws Exception{
        return flowFormService.processOnlineForm(flowInfoId);
    }


    /**
     * 通过lowflow查询字段
     *
     * @param
     * @return
     */
    @GetMapping("/lowFlow")
    @Operation(summary="通过lowflow查询字段",description="通过lowflow查询字段")
    public Result getFlowFieldByFlowFormId(@RequestParam("flowFormId") String flowFormId) throws Exception{
        return flowFormService.getFlowFieldByFlowInfoId(flowFormId);
    }

    /**
     * 流程上线
     *
     * @param
     * @return
     */
    @PostMapping("/processOnline")
    @Operation(summary="流程上线",description="流程上线")
    public Result processOnline(@RequestBody FlowForm flowForm) throws Exception{
        return flowFormService.processOnline(flowForm);
    }

    /**
     * 下线流程
     *
     * @param
     * @return
     */
    @PostMapping("/offlineProcess")
    @Operation(summary="下线流程",description="下线流程")
    public Result offlineProcess(@RequestBody FlowForm flowForm) throws Exception{
        return flowFormService.offlineProcess(flowForm);
    }


}
